<div id='cart_detail'>
      <?php
		
	    extract($_REQUEST, EXTR_PREFIX_ALL|EXTR_REFS, 'v');
		if(isset($v_addmore)){
			$addmore=$v_addmore;
		}
		if(isset($v_bulkadd)){
			$bulkadd=$v_bulkadd;
		}

            if ((isset($addmore) && $addmore == 'Add more') || (isset($bulkadd) && $bulkadd == 'Submit')){
                if (isset($_SESSION['id']) && $_SESSION['id'] <>""){
					$ssid = $_SESSION['id'];
				}else{
					echo "<script type='text/javascript'>alert('session lost here');</script>";
					exit;
				}
				//Finding if Account Belongs to any Distributor Group
				$looking="select * from distributor_groups where distributor='$ssid'";
				$lookingres=mysql_query($looking,$db);
				$rl = mysql_fetch_array($lookingres);
				$grouping=$rl['group'];
				$distributor=$ssid;
                for ($m=1;$m<11;$m++){
                    $cat = "v_cat".$m;
                    if ($$cat <> ''){
                        $catname = "v_cat".$m;
                        $quanname = "v_quan".$m;
                        $prmcdname = "v_prmcd".$m;
                        
                        $catval = strtolower($$catname);
                        $quanval = $$quanname;
                        $prmcdval = strtolower($$prmcdname);
						
						//check if there is a same product ordered under same ID
						$chk="select * from shoplist_dist where sessionid='$ssid' and LOWER(catNo) like '$catval' and LOWER(promotioncode) like '$prmcdval'";
						$chk_res=mysql_query($chk,$db);
						$chk_rw=mysql_num_rows($chk_res);
						if ($chk_rw>0){
							$upd="update shoplist_dist set quantity = quantity + $quanval where sessionid='$ssid' and LOWER(catNo) like '$catval' and LOWER(promotioncode) like '$prmcdval'";
							$ins_res=mysql_query($upd,$db);
						}else{
							
							/****************************************************************/
							/* check pname, price, dbNo, size/unit, supplier, promotioncode */
							/*                                                              */
							/****************************************************************/
							
							switch ($catval){
								default:
									//search Custom Services
									$sql="select * from custom_service where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 15;
										break;
									}
									
									//search antibodies
									$sql="select * from products where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 1;
										break;
									}                                          

                                                //search siRNA Lentivirus
                                                $sql="select * from prodsirna where LOWER(catNo) like '$catval'";
                                                $result=mysql_query($sql,$db);
                                                $row=mysql_num_rows($result);
                                                if ($row>0){
													$csnn=9;
                                                    $dbNo = 2;
                                                    break;
                                                }                                            

                                                //search Lentivirus
                                                $sql="select * from prodlenti where LOWER(catNo) like '$catval'";
                                                $result=mysql_query($sql,$db);
                                                $row=mysql_num_rows($result);
                                                if ($row>0){
													$csnn=10;
                                                    $dbNo = 3;
                                                    break;
                                                }                                            

                                                //search Adenovirus
                                                $sql="select * from prodadenovirus where LOWER(catNo) like '$catval'";
                                                $result=mysql_query($sql,$db);
                                                $row=mysql_num_rows($result);
                                                if ($row>0){
                                                    $dbNo = 4;
													$csnn=11;
                                                    break;
                                                }
								
									//search PCR
									$sql="select * from prodpcr where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 5;
										break;
									}
								
									//search Transfection Reagent
									$sql="select * from prodtrans where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 6;
										break;
									}
								
									//search Viral Expression and iLenti RNAi expression
									$sql="select * from prodviralexp where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 7;
										break;
									}
								
									//search Secondary Antibodies
									$sql="select * from prodsecondanti where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 8;
										break;
									}
								
									//TABLE DOESN'T EXIST ANY MORE
									//search Custom iLenti siRNA
									//$sql="select * from prodrna where LOWER(catNo) like '$catval'";
									//$result=mysql_query($sql,$db);
									//$row=mysql_num_rows($result);
									//if ($row>0){
									//	$dbNo = 9;
									//	break;
									//}
								
									//search DNA/Protein Marker
									$sql="select * from prodmarkers where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 10;
										break;
									}
								
									//search Western Blot
									$sql="select * from prodwesternblot where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 11;
										break;
									}
								
									//search Cell Lysate
									$sql="select * from prodlysates where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 12;
										break;
									}
								
									//search Cell Immortalization
									$sql="select * from prodcellimmort where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 13;
										break;
									}
								
									//search DNA Purification
									$sql="select * from proddnapure where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 14;
										break;
									}
								
									//search Chemicals
									$sql="select * from prodbiochems where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 16;
										break;
									}
								
									//search Antibiotics
									$sql="select * from prodantibiotics where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 17;
										break;
									}
								
									//search Immortalized Primary Cells
									$sql="select * from prodihc where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 18;
										break;
									}
								
									//search miRNA cDNA Synthesis Kit
									$sql="select * from prodcDNAmirna where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 19;
										break;
									}
								
									//search miRNA Expression Vectors
									$sql="select * from premade_mirna_exp where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 26;
										break;
									}
								
									//search miRNA 3'UTR Lenti-Reporter Vectors
									$sql="select * from mirna_validator where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 27;
										break;
									}
								
									//search Individual miRNA Primers Sets
									$sql="select * from mirna_primers_sets where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 28;
										break;
									}
								
									//search Stem Cell Culture
									$sql="select * from prod_cell_culture where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 30; 
										break;
									}
									
									//iPSC Lentivirus
									$sql="select * from prodstemcell where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 31; 
										break;
									}
									
									//iPSC Recombinant Proteins
									$sql="select * from prodprotein where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 32; 
										break;
									}
									
									//iPSC Plasmids
									$sql="select * from prodipscplasmid where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 33; 
										break;
									}
									
									//iPSC Small Molecules
									$sql="select * from prodsmallmolecule where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 34; 
										break;
									}
									
									//iPSC Feeder cell
									$sql="select * from prod_feeder_cell where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 35; 
										break;
									}
									
									//iPSC Growth Factors
									$sql="select * from prod_growth_factor where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 36; 
										break;
									}
									
									//search Primary Cells
									$sql="select * from prod_primary_cells where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 43; 
										break;
									}
								
									//search Protein Purification
									$sql="select * from prodproteinpure where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 44; 
										break;
									}
								
									//search Stable Cell Lines
									$sql="select * from prod_ipsc_cells where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 45; 
										break;
									}
									
									//search iPSC Char. Kits
                                    $sql="select * from prodstemcellkits where LOWER(catNo) like '$catval'";
                                    $result=mysql_query($sql,$db);
                                    $row=mysql_num_rows($result);
                                    if ($row>0){
                                        $dbNo = 46; 
                                        break;
                                    }
									
									//search miRNA Array Profiling Kits
                                    $sql="select * from prodmirnaarray where LOWER(catNo) like '$catval'";
                                    $result=mysql_query($sql,$db);
                                    $row=mysql_num_rows($result);
                                    if ($row>0){
                                        $dbNo = 47; 
                                        break;
                                    }
									
									//search Stable Cell Lines
                                                $sql="select * from prod_cell_lines where LOWER(catNo) like '$catval'";
                                                $result=mysql_query($sql,$db);
                                                $row=mysql_num_rows($result);
                                                if ($row>0){
                                                    $dbNo = 48; 
                                                    break;
                                                }

												//search 3'UTR Cell Lines
                                                $sql="select * from prod_stable_cells where LOWER(catNo) like '$catval'";
                                                $result=mysql_query($sql,$db);
                                                $row=mysql_num_rows($result);
                                                if ($row>0){
                                                    $dbNo = 49; 
                                                    break;
                                                }
									
									//search Diagnostic Kits
                                    $sql="select * from prod_diagnostic_kits where LOWER(catNo) like '$catval'";
                                    $result=mysql_query($sql,$db);
                                    $row=mysql_num_rows($result);
                                                if ($row>0){
                                                    $dbNo = 50; 
                                                    break;
                                                }
									
									//search Diagnostic Kits
					                $sql="select * from prod_equipment where LOWER(catNo) like '$catval'";
					                $result=mysql_query($sql,$db);
                                    $row=mysql_num_rows($result);
				                    if ($row>0){
                                	    $dbNo = 51; 
                                	    break;
                                	}
									
									//search Diagnostic Kits
					                $sql="select * from prodProteinVector where LOWER(catNo) like '$catval'";
					                $result=mysql_query($sql,$db);
                                    $row=mysql_num_rows($result);
				                    if ($row>0){
                                	    $dbNo = 53; 
                                	    $csnn = 53;
                                	    break;
                                	}
									
									//search ORF Vectors
					                $sql="select * from prodORFVector where LOWER(catNo) like '$catval'";
					                $result=mysql_query($sql,$db);
                                    $row=mysql_num_rows($result);
				                    if ($row>0){
                                	    $dbNo = 54;
                                	    $csnn = 54; 
                                	    break;
                                	}
												
									//search Other Products
									$sql="select * from prodothers where LOWER(catNo) like '$catval'";
									$result=mysql_query($sql,$db);
									$row=mysql_num_rows($result);
									if ($row>0){
										$dbNo = 99;
										break;
									}
							}
							
							if ($row > 0){
								$r = mysql_fetch_array($result);
											if($dbNo==12){
												$csnn = $r['csn'];
												if($csn<>23){
													$csnn=56;
												}
											}elseif($dbNo==32){
												$csnn = $r['csn'];
												if($csn<>30){
													$csnn=55;
												}
											}elseif($dbNo<>2&&$dbNo<>3&&$dbNo<>4&&$dbNo<>53&&$dbNo<>54){
                                            	$csnn = $r['csn'];
											}
                                            $ssnn = $r['ssn'];
                                            $dsnn = $r['dsn'];
                                            $pname = $r['pname'];
                                            $catalog = $r['catNo'];
											$testcatno = substr($catalog,0,1);
                                            $orgprice = $r['price'];
											if($orgprice==0&&$dsnn=12288){
												$genename=str_replace("UTR Lenti-reporter-Luc Vector","",$pname);
												$genename=str_replace("UTR Lenti-reporter-GFP Vector","",$genename);
												$genename=substr_replace($genename,"",-7);
												$srchp = "select * from `3primeUTRsequenceProcess` where geneName like '$genename\n' order by totalNumber desc";
												$resp = mysql_query($srchp,$db);
												$rpr = mysql_fetch_array($resp);
												$orgprice = $rpr['price'];
										    }
                                            $inventory = $r['inventory'];
                                            $supplier = $r['supplier'];
											if (isset($r['size'])){
                                                $size = $r['size'];
                                            }elseif (isset ($r['quantity'])){
                                                $size = $r['quantity'];
                                            }else{
											}
												//find discounts for all products for distributors, individual discounts take priority over group discounts and specific discounts take priority over broad category discounts
												$find="select * from distributor_discounts where id_number='$distributor' and csn='$csnn' and ssn='$ssnn' and dsn='$dsnn' and catNo='$catalog'";
												$resulting=mysql_query($find,$db);
												$row7=mysql_num_rows($resulting);
												
												$find1="select * from distributor_discounts where id_number='$distributor' and csn='$csnn' and ssn='$ssnn' and dsn='$dsnn' and catNo='0'";
												$resulting1=mysql_query($find1,$db);
												$row1=mysql_num_rows($resulting1);
												
												$find2="select * from distributor_discounts where id_number='$distributor' and csn='$csnn' and ssn='$ssnn'and dsn='0' and catNo='0'";
												$resulting2=mysql_query($find2,$db);
												$row2=mysql_num_rows($resulting2);
												
												$find3="select * from distributor_discounts where id_number='$distributor' and csn='$csnn' and ssn='0'and dsn='0' and catNo='0'";
												$resulting3=mysql_query($find3,$db);
												$row3=mysql_num_rows($resulting3);
												
												$find4="select * from distributor_discounts where id_number='$distributor' and csn='0'";
												$resulting4=mysql_query($find4,$db);
												$row4=mysql_num_rows($resulting4);
												
												$find5="select * from distributor_group_discounts where group_number='$grouping' and csn='$csnn' and ssn='$ssnn' and dsn='$dsnn' and catNo='$catalog'";
												$resulting5=mysql_query($find5,$db);
												$row5=mysql_num_rows($resulting5);
												
												$find6="select * from distributor_group_discounts where group_number='$grouping' and csn='$csnn' and ssn='$ssnn' and dsn='$dsnn' and catNo='0'";
												$resulting6=mysql_query($find6,$db);
												$row6=mysql_num_rows($resulting6);
												
												$find8="select * from distributor_group_discounts where group_number='$grouping' and csn='$csnn' and ssn='$ssnn'and dsn='0' and catNo='0'";
												$resulting8=mysql_query($find8,$db);
												$row8=mysql_num_rows($resulting8);
												
												$find9="select * from distributor_group_discounts where group_number='$grouping' and csn='$csnn' and ssn='0'and dsn='0' and catNo='0'";
												$resulting9=mysql_query($find9,$db);
												$row9=mysql_num_rows($resulting9);
												
												$find10="select * from distributor_group_discounts where group_number='$grouping' and csn='0'";
												$resulting10=mysql_query($find10,$db);
												$row10=mysql_num_rows($resulting10);
												
												//For G*** Cat. No. Antibodies turns them into 'Tag Antibodes' Discount for Groups
												if($testcatno=='G' && $dbNo==1){
													$find35="select * from distributor_group_discounts where group_number='$grouping' and csn='17' and ssn='0'and dsn='0' and catNo='0'";
													$resulting35=mysql_query($find35,$db);
													$row35=mysql_num_rows($resulting35);
													
													$find36="select * from distributor_discounts where id_number='$distributor' and csn='17' and ssn='0'and dsn='0' and catNo='0'";
													$resulting36=mysql_query($find36,$db);
													$row36=mysql_num_rows($resulting36);
												}else{
													$row35=0;
													$row36=0;
												}
												
												$find44="select * from supplier_allowableAccounts where account='$distributor'";
												$resulting44=mysql_query($find44,$db);
												$row44=mysql_num_rows($resulting44);
												if($row44>0 && ($dbNo==1 || $dbNo==8)){
													$find33="select * from supplier_discounts where supplier like '%$supplier%'";
													$resulting33=mysql_query($find33,$db);
													$row33=mysql_num_rows($resulting33);
												}else{
													$row33=0;
												}
												
												if ($row7>0){
													$rf = mysql_fetch_array($resulting);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row5>0){
													$rf = mysql_fetch_array($resulting5);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row1>0){
													$rf = mysql_fetch_array($resulting1);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row6>0){
													$rf = mysql_fetch_array($resulting6);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row2>0){
													$rf = mysql_fetch_array($resulting2);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row8>0){
													$rf = mysql_fetch_array($resulting8);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row3>0){
													$rf = mysql_fetch_array($resulting3);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row9>0){
													$rf = mysql_fetch_array($resulting9);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row4>0){
													$rf = mysql_fetch_array($resulting4);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row10>0){
													$rf = mysql_fetch_array($resulting10);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row36>0){
													$rf = mysql_fetch_array($resulting36);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row35>0){
													$rf = mysql_fetch_array($resulting35);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif ($row33>0){
													$rf = mysql_fetch_array($resulting33);
													$discountper=$rf['percentage_off'];
													$discountamt=$orgprice*$discountper;
													$price=$orgprice-$discountamt;
												}elseif($prmcdval<>""){
													//For Finding Promotion Code Discounts, only valid if no other discounts found first
													$findpromo1="select * from distributor_promo where promo_code='$prmcdval' and csn='$csnn' and ssn='$ssnn' and dsn='$dsnn' and catNo='$catalog'";
													$resultingpromo1=mysql_query($findpromo1,$db);
													$rowp1=mysql_num_rows($resultingpromo1);
													
													$findpromo2="select * from distributor_promo where promo_code='$prmcdval' and csn='$csnn' and ssn='$ssnn' and dsn='$dsnn' and catNo='0'";
													$resultingpromo2=mysql_query($findpromo2,$db);
													$rowp2=mysql_num_rows($resultingpromo2);
													
													$findpromo3="select * from distributor_promo where promo_code='$prmcdval' and csn='$csnn' and ssn='$ssnn' and dsn='0' and catNo='0'";
													$resultingpromo3=mysql_query($findpromo3,$db);
													$rowp3=mysql_num_rows($resultingpromo3);
													
													$findpromo4="select * from distributor_promo where promo_code='$prmcdval' and csn='$csnn' and ssn='0' and dsn='0' and catNo='0'";
													$resultingpromo4=mysql_query($findpromo4,$db);
													$rowp4=mysql_num_rows($resultingpromo4);
													
													$findpromo5="select * from distributor_promo where promo_code='$prmcdval' and csn='0';";
													$resultingpromo5=mysql_query($findpromo5,$db);
													$rowp5=mysql_num_rows($resultingpromo5);
													
													if($rowp1>0){
														$rf = mysql_fetch_array($resultingpromo1);
														$discountper=$rf['percentage_off'];
														$discountamt=$orgprice*$discountper;
														$price=$orgprice-$discountamt;
													}elseif($rowp2>0){
														$rf = mysql_fetch_array($resultingpromo2);
														$discountper=$rf['percentage_off'];
														$discountamt=$orgprice*$discountper;
														$price=$orgprice-$discountamt;
													}elseif($rowp3>0){
														$rf = mysql_fetch_array($resultingpromo3);
														$discountper=$rf['percentage_off'];
														$discountamt=$orgprice*$discountper;
														$price=$orgprice-$discountamt;
													}elseif($rowp4>0){
														$rf = mysql_fetch_array($resultingpromo4);
														$discountper=$rf['percentage_off'];
														$discountamt=$orgprice*$discountper;
														$price=$orgprice-$discountamt;
													}elseif($rowp5>0){
														$rf = mysql_fetch_array($resultingpromo5);
														$discountper=$rf['percentage_off'];
														$discountamt=$orgprice*$discountper;
														$price=$orgprice-$discountamt;
													}else{
														$discountper=0.0;
														$discountamt=0.00;
														$price=$orgprice;
													}
												}else{
													$discountper=0.0;
													$discountamt=0.00;
													$price=$orgprice;
												}
												//Find Shipping Conditions for Product
												$find="select * from distributor_shipping where csn='$csnn' and ssn='$ssnn' and dsn='$dsnn' and catNo='$catalog'";
												$resulting=mysql_query($find,$db);
												$row7=mysql_num_rows($resulting);
												
												$find1="select * from distributor_shipping where csn='$csnn' and ssn='$ssnn' and dsn='$dsnn' and catNo='0'";
												$resulting1=mysql_query($find1,$db);
												$row1=mysql_num_rows($resulting1);
												
												$find2="select * from distributor_shipping where csn='$csnn' and ssn='$ssnn' and dsn='0' and catNo='0'";
												$resulting2=mysql_query($find2,$db);
												$row2=mysql_num_rows($resulting2);
												
												$find3="select * from distributor_shipping where csn='$csnn' and ssn='0' and dsn='0' and catNo='0'";
												$resulting3=mysql_query($find3,$db);
												$row3=mysql_num_rows($resulting3);
												
												$find4="select * from distributor_shipping where csn='0'";
												$resulting4=mysql_query($find4,$db);
												$row4=mysql_num_rows($resulting4);
												
												if ($row7>0){
													$rf = mysql_fetch_array($resulting);
													$conditions=$rf['conditions'];
												}elseif ($row1>0){
													$rf = mysql_fetch_array($resulting1);
													$conditions=$rf['conditions'];
												}elseif ($row2>0){
													$rf = mysql_fetch_array($resulting2);
													$conditions=$rf['conditions'];
												}elseif ($row3>0){
													$rf = mysql_fetch_array($resulting3);
													$conditions=$rf['conditions'];
												}elseif ($row4>0){
													$rf = mysql_fetch_array($resulting4);
													$conditions=$rf['conditions'];
												}else{
													$conditions='N/A';
												}
                                        //Insert item into shopping cart
                                        $ins = "insert into shoplist_dist (catNo,csnNumber,ssnNumber,dsnNumber,dbNo,pname,sessionid,unit,org_price,discount_percent,discount_amount,price,quantity,supplier,shipping,inventory,promotioncode) 
                                        values ('$catalog',$csnn,$ssnn,$dsnn,'$dbNo','$pname','$ssid','$size','$orgprice','$discountper','$discountamt','$price','$quanval','$supplier','$conditions','$inventory','$prmcdval')";
                                        $ins_res = mysql_query($ins,$db);

                                        }else{
                                            echo "<script language=javascript>alert('$catval not found, rest of products added successfully to the cart.');</script>";
                                        }
				}
                    }
                }
            }
          ?>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <th width="17%" height="40">Cat. No.</th>
              <th width="38%">Product Name</th>
              <th width="6%" style="text-align:center;">Qty.</th>
              <th width="14%" style="text-align:center;">Promo/% Off</th>
              <th width="10%" style="text-align:right;">Amount </th>
              <th width="7%"></th>
              <th width="8%"></th>
            </tr>
            <?php
				//shopping cart list
				$id=$_SESSION['id'];
				$crt="select * from shoplist_dist where sessionid='$id'";
				$crtres=mysql_query($crt,$db);
				$crtrw=mysql_num_rows($crtres);
				if ($crtrw>0){
					$discnttotal = 0.00;
					$total=0.00;
					while ($cr=mysql_fetch_array($crtres)){
						$shpcatno = $cr['catNo'];
						$sn = $cr['sn'];
						$subtotal = $cr['price'] * $cr['quantity'];
						$pname = $cr['pname'];
						$discountperitem = $cr['discount_percent']*100;
						$quan = $cr['quantity'];
						$total += $subtotal;
						$promocode = $cr['promotioncode'];
						$subtotaldef=number_format($subtotal, 2, '.', '');
						echo "
          				<form id='form2' name='form2' method='post' action='#cart'>
						  <tr>
							<td>$shpcatno</td>
							<td>$pname</td>
							<td style='text-align:center;'><input name='qtychg' type='text' id='qtychg' size='2' value='$quan' /></td>
							<td align='center'>";
							if($discountperitem<>'0'){
								echo"$discountperitem%";
							}else{
								echo"<input name='pmcode' type='text' id='pmcode' size='3' value='$promocode' />";
							}
							echo"</td>
							<td  style='text-align:right;'><input name='subtotal' type='hidden' id='subtotal' size='5' value='$$subtotal' />$$subtotaldef </td>
							<td><input name='cart' type='hidden' value='1' />
								<input name='csn' type='hidden' id='csn' value='$csn'/>
								<input name='ssn' type='hidden' id='ssn' value='$ssn'/>
								<input name='dsn' type='hidden' id='dsn' value='$dsn'/>
								<input name='pcat' type='hidden' id='pcat' value='$csn'/>
								<input name='shpsn' type='hidden' id='shpsn' value='$sn'/>
								<input name='catno' type='hidden' id='catno' value='$catno'/>
								";
                                    if(isset($mirnagene)&&$mirnagene<>''){
                                        echo"<input name='mirnagene' type='hidden' id='mirnagene' value='$mirnagene'/>";
                                    }
                                    if(isset($mirnaid)&&$mirnaid<>''){
                                        echo"<input name='mirnaid' type='hidden' id='mirnaid' value='$mirnaid'/>";
                                    }
									if (isset($genename)){ 
										echo "<input id='genename' name='genename' type='hidden' value='$genename' />";
									}
									if (isset($access)){ 
										echo "<input id='access' name='access' type='hidden' value='$access' />";
									}
									if (isset($species)){ 
										echo "<input id='species' name='species' type='hidden' value='$species' />";
									}
									if (isset($report)){ 
										echo "<input id='report' name='report' type='hidden' value='$report' />";
									}
                                    echo"
								<input type='submit' name='button' id='button' title='Update Item' value='Update' />
							</td>
							<td><input type='submit' name='button2' id='button2' title='Remove Item from Cart' value='Remove' /></td>
						  </tr>
						</form>";
					}
					echo"
					  <tr style='border-top:1px solid #E98F4E;'>
						<td height='24' colspan='2' style='border-top:1px solid #E98F4E;'>
						<form id='form32' name='form32' method='post' action='/cart-checkout.php'>
						
							<input type='Submit' name='button3' id='button3' title='Check Out' value='Check Out' />
							<input name='sessionpass' type='hidden' id='sessionpass' value='".$_SESSION['id']."'/>
						</form>
						<form id='form3' name='form3' method='post' action='#cart'>
							<input name='cart' type='hidden' value='1' />
							<input name='csn' type='hidden' id='csn' value='$csn'/>
							<input name='ssn' type='hidden' id='ssn' value='$ssn'/>
							<input name='dsn' type='hidden' id='dsn' value='$dsn'/>";
                                    if(isset($mirnagene)&&$mirnagene<>''){
                                        echo"<input name='mirnagene' type='hidden' id='mirnagene' value='$mirnagene'/>";
                                    }
                                    if(isset($mirnaid)&&$mirnaid<>''){
                                        echo"<input name='mirnaid' type='hidden' id='mirnaid' value='$mirnaid'/>";
                                    }
									if (isset($genename)){ 
										echo "<input id='genename' name='genename' type='hidden' value='$genename' />";
									}
									if (isset($access)){ 
										echo "<input id='access' name='access' type='hidden' value='$access' />";
									}
									if (isset($species)){ 
										echo "<input id='species' name='species' type='hidden' value='$species' />";
									}
									if (isset($report)){ 
										echo "<input id='report' name='report' type='hidden' value='$report' />";
									}
                                    echo"
						</td>
						<td style='border-top:1px solid #E98F4E;'>
						  	<input type='Submit' name='button4' id='button4' title='Quick Order' value='Quick Order' /></td>";
						if($discnttotal==0){
							echo"<td style='border-top:1px solid #E98F4E; color:#000; text-align:right; padding-right:5px;'>&nbsp;</td>
						<td style='border-top:1px solid #E98F4E;'><input name='subtotal' type='text' id='subtotal' size='5' value='' readonly='readonly' /></td>";
						}else{
							$discnttotaldef=number_format($discnttotal, 2, '.', '');
							echo"
						<td style='border-top:1px solid #E98F4E; color:#000; text-align:right; padding-right:5px;'>Discount:</td>
						<td style='border-top:1px solid #E98F4E;' align='right'><input name='subtotal' type='hidden' id='subtotal' size='5' value='- $$discnttotaldef' />- $$discnttotaldef</td>";
						}
						echo"						
						<td colspan='3' style='border-top:1px solid #E98F4E; text-align:right;'><input type='submit' name='button5' id='button5' title='Remove All Items from Cart' value='Clear All' /></td>
					  </tr>
					</form>";
				}else{
					echo "
          			<form id='form3' name='form3' method='post' action='#cart'>
					  <tr style='border-top:1px solid #E98F4E;'>
						<td height='24' colspan='2' style='border-top:1px solid #E98F4E;'>
						  <input name='cart' type='hidden' value='1' />
						  ";
                                    if(isset($mirnagene)&&$mirnagene<>''){
                                        echo"<input name='mirnagene' type='hidden' id='mirnagene' value='$mirnagene'/>";
                                    }
                                    if(isset($mirnaid)&&$mirnaid<>''){
                                        echo"<input name='mirnaid' type='hidden' id='mirnaid' value='$mirnaid'/>";
                                    }
									if (isset($genename)){ 
										echo "<input id='genename' name='genename' type='hidden' value='$genename' />";
									}
									if (isset($access)){ 
										echo "<input id='access' name='access' type='hidden' value='$access' />";
									}
                                    echo"
						  <input type='Submit' name='button4' id='button4' value='Quick Order' />
						</td>
						<td style='border-top:1px solid #E98F4E;'>&nbsp;</td>
						<td style='border-top:1px solid #E98F4E; color:#000; text-align:right; padding-right:5px;'>&nbsp;</td>
						<td style='border-top:1px solid #E98F4E;'>&nbsp;</td>
						<td colspan='3' style='border-top:1px solid #E98F4E; text-align:right;'>&nbsp;</td>
					  </tr>
					</form>";
				}
				if(!isset($total)){$total=0;}
				$totaldef=number_format($total, 2, '.', '');
            ?>
            <tr>
              <td colspan="2" height="10">&nbsp;</td>
              <td>&nbsp;</td>
              <td style="text-align:right; padding-right:5px;font-weight:bold;">Total: </td>
              <td style="text-align:right;"><input name="total" type="hidden" id="total" size="5" value="<?php if (isset($total)){echo "$".$total;}else{echo "$0";}?>" /><?php if (isset($total)){echo "$".$totaldef;}else{echo "$0";}?> </td>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td colspan="7" height="10" style='font-size:9px'>*Notes about Promo Codes: For NON-DISCOUNT promo codes (i.e. free items or shipping) please enter them during check out in the Notes/Promo Code field. To enter a DISCOUNT promo code enter it into the corresponding box in the 'Promo/% Off' column and then click 'Update' for the given product. If the code is valid for that product the discount percentage will display in place of the box and the amount will become the discounted total for that product(s). If the code is not valid it will remain in the box, please double check the expiry and spelling, and if you feel the code should still be accepted please contact us.</td>
            </tr>
          </table>
          <div id='quickadd'>
            <form id="form4" name="form4" method="post" action="">
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr style="font-weight:bold;">
                  <td width="41%" height="33" align="center">Catalog Number</td>
                  <td width="17%" align="center">Quantity</td>
                  <td width="42%" align="center">Promotion Code (Optional)</td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat1" id="cat1" /></td>
                  <td align="center"><input name="quan1" type="text" id="quan1" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd1" id="prmcd1" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat2" id="cat2" /></td>
                  <td align="center"><input name="quan2" type="text" id="quan2" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd2" id="prmcd2" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat3" id="cat3" /></td>
                  <td align="center"><input name="quan3" type="text" id="quan3" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd3" id="prmcd3" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat4" id="cat4" /></td>
                  <td align="center"><input name="quan4" type="text" id="quan4" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd4" id="prmcd4" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat5" id="cat5" /></td>
                  <td align="center"><input name="quan5" type="text" id="quan5" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd5" id="prmcd5" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat6" id="cat6" /></td>
                  <td align="center"><input name="quan6" type="text" id="quan6" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd6" id="prmcd6" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat7" id="cat7" /></td>
                  <td align="center"><input name="quan7" type="text" id="quan7" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd7" id="prmcd7" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat8" id="cat8" /></td>
                  <td align="center"><input name="quan8" type="text" id="quan8" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd8" id="prmcd8" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat9" id="cat9" /></td>
                  <td align="center"><input name="quan9" type="text" id="quan9" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd9" id="prmcd9" /></td>
                </tr>
                <tr>
                  <td align="center"><input type="text" name="cat10" id="cat10" /></td>
                  <td align="center"><input name="quan10" type="text" id="quan10" value="1" size="5" /></td>
                  <td align="center"><input type="text" name="prmcd10" id="prmcd10" /></td>
                </tr>
                <tr>
                  <td height="33" align="center">&nbsp;</td>
                  <td align="center">&nbsp;</td>
                  <td align="center">
                  	<input name='cart' type='hidden' value='1' />
                  	<input type="submit" name="addmore" id="addmore" value="Add more" />
                    <input type="submit" name="bulkadd" id="bulkadd" value="Submit" /></td>
                </tr>
              </table>
            </form>
          </div>
</div>
<?php
	if (($cart)%2 == 0){
		echo "<script language=javascript>document.getElementById('cart_detail').style.display='none';</script>";
	}else{
		echo "<script language=javascript>document.getElementById('cart_detail').style.display='block'; document.getElementById('carttab').src='/images/cart-up.png';</script>";
	}
	
	if (isset($button4) && $button4 == 'Quick Order' ){
		echo "<script language=javascript>document.getElementById('quickadd').style.display='block'; </script>";
	}
	
	if (isset($bulkadd)){
		echo "<script language=javascript>document.getElementById('quickadd').style.display = 'none';</script>";
	}
	
	if (isset($addmore)){
		echo "<script language=javascript>document.getElementById('quickadd').style.display = 'block';</script>";
	}
?>
